from tortoise import fields
from .base import BaseModel, TimestampMixin

class Buckling(BaseModel, TimestampMixin):
    order_id = fields.IntField(default=0, description="订单id")
    goods_id = fields.IntField(default=0, description="商品id")
    sku_id = fields.IntField(default=0, description="规格id")
    user_id = fields.IntField(default=0, description="用户id")
    nums = fields.IntField(default=0, description="数量")
    direction = fields.IntField(default=1, max_length=10, description="变动方向1增加2减少")
    add_uid = fields.IntField(default=0, description="录入人id")
    space_id = fields.IntField(default=0, description="门店id")
    use_nums = fields.IntField(default=0, description="使用次数")
    last_nums = fields.IntField(default=0, description="剩余次数")
    price = fields.DecimalField(max_digits=10, decimal_places=2, description="划扣总金额")
    todo_id = fields.IntField(default=0, description="todo_id")
    over_date = fields.DateField(max_length=255, null=True, description="超期时间")
    group_id = fields.IntField(default=0, description="saas_buckling_group表id")

    class Meta:
        table = "saas_buckling"

class Cases(BaseModel, TimestampMixin):
    user_id = fields.IntField(default=0, description="用户id")
    add_uid = fields.IntField(default=0, description="录入人id")
    space_id = fields.IntField(default=0, description="门店id")
    desc = fields.CharField(max_length=255,description="备注")
    files = fields.JSONField(null=True, description="关联凭证")
    designer_ids = fields.JSONField(null=True, description="技师ids")
    buckling_data = fields.JSONField(null=True, description="明细")
    buckling_consumables = fields.JSONField(null=True, description="划扣耗材明细")
    e_sign = fields.CharField(max_length=255, null=True, description="电子签名")
    other_form = fields.JSONField(null=True, description="其他表单")
    before_pic = fields.JSONField(null=True, description="术前图片")
    after_pic = fields.JSONField(null=True, description="术后图片")

    class Meta:
        table = "saas_cases"

class BucklingDetail(BaseModel, TimestampMixin):
    buckling_id = fields.IntField(default=0, description="buckling_id")
    cases_id = fields.IntField(default=0, description="病例id")
    nums = fields.IntField(default=0, description="数量")
    buckling_price = fields.DecimalField(max_digits=10, decimal_places=2, description="划扣金额")

    class Meta:
        table = "saas_buckling_detail"

class BucklingTodo(BaseModel, TimestampMixin):
    order_id = fields.IntField(default=0, description="订单id")
    user_id = fields.IntField(default=0, description="用户id")
    goods_id = fields.IntField(default=0, description="商品id")
    sku_id = fields.IntField(default=0, description="sku_id")
    project_id = fields.IntField(default=0, description="项目id")
    type = fields.IntField(default=1, description="1项目2套餐卡")
    status = fields.IntField(default=0, description="0未开卡1疗程中2已结束")
    price = fields.IntField(default=0, description="划分价值")
    nums = fields.IntField(default=1, description="数量")
    order_goods_id = fields.IntField(default=0, description="order_goods表的id")
    start_date = fields.DateField(max_length=255, null=True, description="开卡时间")
    space_id = fields.IntField(default=0,null=True, description="开卡门店")

    class Meta:
        table = "saas_buckling_todo"

class BucklingGroup(BaseModel, TimestampMixin):
    type = fields.IntField(default=1, description="1必得2选择")
    todo_id = fields.IntField(default=0, description="BucklingTodo表的id")
    group_id = fields.IntField(default=0, description="组合包id")
    group_name = fields.CharField(max_length=255, null=True, description="组合包名称")
    group_type = fields.IntField(default=0, description="类型1分次2总次3时段")
    times = fields.IntField(default=0, description="总次数/时长")
    over_date = fields.DateField(max_length=255, null=True, description="超期时间")
    use_times = fields.IntField(default=0, description="使用次数")
    last_times = fields.IntField(default=0, description="剩余次数")

    class Meta:
        table = "saas_buckling_group"

class BucklingGive(BaseModel, TimestampMixin):
    order_id = fields.IntField(default=0, description="订单id")
    order_goods_id = fields.IntField(default=0, description="订单商品id")
    buckling_todo_id = fields.IntField(default=0, description="BucklingTodo表的id")
    new_customer_id = fields.IntField(default=0, description="被赠送者id")
    giver_customer_id = fields.IntField(default=0, description="赠送者id")
    add_uid = fields.IntField(default=0, description="操作人id")

    class Meta:
        table = "saas_buckling_give"

class SchedulingRules(BaseModel, TimestampMixin):
    label = fields.TextField(default="", description="名称", null=True)
    start = fields.TextField(default="", description="开始时间", null=True)
    end = fields.TextField(default="", description="结束时间", null=True)
    color = fields.TextField(default="", description="颜色1", null=True)

    class Meta:
        table = "saas_scheduling_rule"

class SchedulingDates(BaseModel, TimestampMixin):
    rules_id = fields.IntField(default=0, description="rules_id")
    designer_id = fields.IntField(default=0,null=True, description="技师id")
    date = fields.TextField(default="", description="日期", null=True)
    start = fields.TextField(default="", description="开始时间", null=True)
    end = fields.TextField(default="", description="结束时间", null=True)
    space_id = fields.IntField(default=0, description="门店id")

    class Meta:
        table = "saas_scheduling_dates"

class Consumables(BaseModel, TimestampMixin):
    name = fields.TextField(default="", description="耗材名称", null=True)
    guige = fields.TextField(default="", description="规格")
    danwei = fields.TextField(default="", description="单位")
    order = fields.IntField(default=0, description="排序")
    type = fields.IntField(default=1, description="类型")

    class Meta:
        table = "saas_consumables"

class ConsumablesUse(BaseModel, TimestampMixin):
    consumables_id = fields.IntField(default=0, description="耗材id")
    nums = fields.DecimalField(max_digits=10, decimal_places=2, description="耗材使用数量")
    user_id = fields.IntField(default=0, description="用户id")
    # buckling_id = fields.IntField(default=0, description="待划扣id")
    # buckling_detail_id = fields.IntField(default=0, description="划扣记录id")
    cases_id = fields.IntField(default=0, description="病例id")

    class Meta:
        table = "saas_consumables_use"

class UserLog(BaseModel, TimestampMixin):
    user_id = fields.IntField(default=0, description="员工小程序用户id")
    data = fields.TextField(default="", description="记录值")

    class Meta:
        table = "saas_user_log"

class PerformancePercentage(BaseModel, TimestampMixin):
    order_id = fields.IntField(default=0, description="订单id")
    goods_id = fields.IntField(default=0, description="商品id")
    sku_id = fields.IntField(default=0, description="sku_id")
    customer_id = fields.IntField(default=0, description="客户id")
    user_id = fields.IntField(default=0, description="员工id")
    space_id = fields.IntField(default=0, description="门店id")
    price = fields.DecimalField(max_digits=10, decimal_places=2, description="业绩金额")
    buckling_id = fields.IntField(default=0, description="待划扣id")
    status = fields.IntField(default=0, description="审核状态")

    class Meta:
        table = "saas_performance_percentage"